home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 June / EnigmA AMIGA RUN 08 (1996)(G.R. Edizioni)(IT)[!][issue 1996-06][EARSAN CD VII].iso / earcd / games1 / tahckv10.lha / TA-Hack / source / FindTaskExt.c next >
C/C++ Source or Header  |  1996-04-14  |  2KB  |  59 lines

  1. #include <exec/memory.h>
  2. #include <exec/execbase.h>
  3. #define __USE_SYSBASE
  4. #include <proto/exec.h>
  5. #include <dos/dosextens.h>
  6. #include <string.h>
  7.  
  8. #include "FindTaskExt.h"
  9.  
  10. #define b2c(bptr,type) ( (type) ((ULONG)(bptr) << 2))
  11.  
  12. struct Task *FindTaskExt(char *name, BOOL casesensitive, ULONG *type){
  13.     char cname[80], blen;
  14.     struct Process *proc;
  15.     char *bname, i;
  16.     ULONG dummy_type;
  17.     
  18.     if(!type){
  19.         type=&dummy_type;
  20.         *type = FT_TASK | FT_PROCESS | FT_COMMAND;
  21.     }
  22.     
  23.     Forbid();
  24.     for(i=0; i<2; i++){
  25.         if(i)
  26.             proc = (struct Process *) SysBase->TaskWait.lh_Head;
  27.         else
  28.             proc = (struct Process *) SysBase->TaskReady.lh_Head;
  29.         while(proc->pr_Task.tc_Node.ln_Succ){
  30.             if((strcmp(proc->pr_Task.tc_Node.ln_Name, name)==0) || (!casesensitive && stricmp(proc->pr_Task.tc_Node.ln_Name, name)==0)){
  31.                 if((*type & FT_TASK) && (proc->pr_Task.tc_Node.ln_Type == NT_TASK)){
  32.                     *type = FT_TASK;
  33.                     goto exit;
  34.                 }else if ((*type & FT_PROCESS) && (proc->pr_Task.tc_Node.ln_Type == NT_PROCESS)){
  35.                     *type = FT_PROCESS;
  36.                     goto exit;
  37.                 }
  38.             }else if((*type & FT_COMMAND) &&
  39.                         (proc->pr_Task.tc_Node.ln_Type==NT_PROCESS) &&
  40.                       (proc->pr_CLI) &&
  41.                       (b2c(proc->pr_CLI, struct CommandLineInterface *)->cli_Module) &&
  42.                       (bname = b2c(b2c(proc->pr_CLI, struct CommandLineInterface *)->cli_CommandName, char *))){
  43.               memcpy(cname, bname+1, blen=*bname);
  44.               cname[blen]=0;
  45.               if((strcmp(cname,name)==0) || (!casesensitive && stricmp(cname,name)==0)){
  46.                   *type = FT_COMMAND;
  47.                   goto exit;
  48.               }
  49.            }
  50.            proc = (struct Process *) proc->pr_Task.tc_Node.ln_Succ;
  51.         }
  52.     }
  53.     proc = NULL;
  54.     *type = FT_NONE;
  55.     exit:
  56.     Permit();
  57.     return((struct Task *)proc);
  58. }
  59.